package com.smart.manager.pop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ExceptionTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.pop.entities.body.RBasicDiamond;
import com.smart.manager.pop.entities.models.PopBasicDiamond;
import com.smart.manager.pop.repository.PopBasicDiamondRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * 礼包资料
 * @author leo
 * @date 2023/09/07
 */
@Api(tags =  "礼包礼包")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "pop/basic/diamond")
@RequiredArgsConstructor
public class BasicDiamondApi {

    private final PopBasicDiamondRepository repository;
    
    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询礼包")
    @SaCheckPermission("pop:diamond:pageList")
    public AjaxResult<Page<PopBasicDiamond>> pageList(@Validated RBasicDiamond.SearchBody body) {
        Page<PopBasicDiamond> result = repository.pageList(body);
        return AjaxResult.data(result);
    }

    @ApiOperation(value = "添加礼包")
    @PostMapping("add")
    @SaCheckPermission("pop:diamond:add")
    public AjaxResult<String> add(@RequestBody @Validated RBasicDiamond.EditBody data) {
        repository.add( data );
        return AjaxResult.success();
    }


    @ApiOperation(value = "修改礼包")
    @PutMapping("update/{id}")
    @SaCheckPermission("pop:diamond:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RBasicDiamond.EditBody data) {
        repository.update( id, data );
        return AjaxResult.success();
    }


    @ApiOperation(value = "删除礼包")
    @DeleteMapping("delete")
    @SaCheckPermission("pop:diamond:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ExceptionTips.PK_EMPTY) List<Long> ids) {
        int i = repository.delByIds( ids );
        return AjaxResult.delSuccess( i );
    }

}
